<%@page import="com.bill.common.utils.TranType"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.bill.common.system.dto.SingleGroupReportStatDTO"%>
<%@page import="com.sinba.common.dto.PageDTO"%>
<%@page import="com.bill.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.bill.common.system.service.ITransactionRecordService"%>
<%@page import="com.bill.common.user.service.IAccountService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="../language.jsp" %>
<%

String[] transactionTypes = {};
String dtype="dtype";
if(request.getParameter("dtype")!=null){
	dtype=request.getParameter("dtype");
	if(TranType.DYNAMIC.equals(dtype)){
		transactionTypes = TranType.DynamicsAccount;
	}
	if(TranType.OTHER1.equals(dtype)){
		transactionTypes = TranType.Other1Account;
	}
	if(TranType.OTHER2.equals(dtype)){
		transactionTypes = TranType.Other2Account;
	}
	if(TranType.STATIC.equals(dtype)){
		transactionTypes = TranType.SubAccount;
	}
}
request.setAttribute("dtype",dtype);

if(session.getAttribute("password2")==null){
	response.sendRedirect( "login2.jsp?pageUrl=user/accountDetails.jsp?dtype="+dtype);
	return;
}

ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setLoginName((String)session.getAttribute("loginName"));
int pages = 1;
String sidx = "recordId";
String sord="desc";
Object param1 = request.getParameter("trDTO.transactionType");

if(param1!=null 
&& param1!="" 
&& !"null".equals(param1)){
	trDTO.setTransactionType(request.getParameter("trDTO.transactionType"));
	pages=1;
}
if(request.getParameter("pages")!=null && request.getParameter("pages")!=""){
	pages = Integer.parseInt(request.getParameter("pages"));
}
int rows = 10;
int start = ( pages - 1 ) * rows;
trDTO.setStart( start );
trDTO.setLimit( rows );

trDTO.setDtype(dtype);
PageDTO pageDTO = transactionRecordService.findTransactionRecordPager(trDTO, sord, sidx);
if(pageDTO!=null){
	pageDTO.setPage( pages );
	pageDTO.setRows( rows );
}
request.setAttribute("pageDTO",pageDTO);

//统计：
Double income = 0D;
TransactionRecordDTO trDto1 = new TransactionRecordDTO();
trDto1.setInOrExp("income");
trDto1.setDtype(dtype);
trDto1.setLoginName((String)session.getAttribute("loginName"));
List<SingleGroupReportStatDTO> sgrs = transactionRecordService.statAccount(trDto1);
for(SingleGroupReportStatDTO sgr : sgrs){
	if(sgr.getAggField()!=null){
		income = income+sgr.getAggField();
	}
}
request.setAttribute("income",income);


Double expenditure = 0D;
TransactionRecordDTO trDto2 = new TransactionRecordDTO();
trDto2.setInOrExp("expenditure");
trDto2.setDtype(dtype);
trDto2.setLoginName((String)session.getAttribute("loginName"));
List<SingleGroupReportStatDTO> sgrs2 = transactionRecordService.statAccount(trDto2);
for(SingleGroupReportStatDTO sgr : sgrs2){
	if(sgr.getAggField()!=null){
		expenditure = expenditure+sgr.getAggField();
	}
}
request.setAttribute("expenditure",expenditure);
request.setAttribute("transactionTypes", transactionTypes);

request.setAttribute("pageUrl","accountDetails.jsp?dtype="+dtype+"&loginName="+ trDto1.getLoginName());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><fmt:message key="i18n.title"/> </title>
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	
	<link rel="shortcut icon" href="../index/favicon.png" />
	
	<!-- bootstrap -->
    <link href="css/bootstrap/bootstrap.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/bootstrap/bootstrap-overrides.css" type="text/css" rel="stylesheet" />

    <!-- global styles -->
    <link rel="stylesheet" type="text/css" href="css/elements.css" />
    <link rel="stylesheet" type="text/css" href="css/icons.css" />
    
	<!-- this page specific styles -->
    <link rel="stylesheet" href="css/compiled/tables.css" type="text/css" media="screen" />
	 
	<link rel="stylesheet" href="../styles/myStyle.css" />
	 
</head>
<body>
	<!-- main container -->
	<div class="content container-fluid">
		<!-- BreadcrumbNavigation -->
        <div class="row-fluid head">
            <div class="span12">
                <h4><fmt:message key="detailQuery"/> &gt; <fmt:message key="${dtype }" /></h4>
            </div>
        </div>
        <!-- End BreadcrumbNavigation -->
        
        <!-- list table -->
        <div class="table-wrapper orders-table section">
        	<div class="row-fluid head">
                <div class="span12">
                    <p style="color:red;font-weight: 200"> 
                    	<fmt:message key="i18n.totalincome"/>:<fmt:formatNumber value="${income}" pattern="#0.0000"/> ，
						<fmt:message key="i18n.totalZhichu"/>：<fmt:formatNumber value="${expenditure}" pattern="#0.0000"/>
					</p>
                </div>
            </div>
			<form id="bonusSeachForm" action="${pageUrl}" method="post">
			<input name="sidx" value="recordId" type="hidden" >
			<input name="sord" value="desc" type="hidden" >
			<input name="trDTO.searchType" value="bonus" type="hidden" >
			<input name="trDTO.loginName" value="${session.loginName }" type="hidden" >
            <div class="row-fluid filter-block">
                <div class="pull-left">
                    <div class="ui-select">
                        <select class="tx_contBoxR2_1" name="trDTO.transactionType" style="height: 28px;">
					 	   	<option value="">--<fmt:message key="i18n.pelaseSelect"/>--</option>
					 	   	<c:forEach items="${transactionTypes}" var="tts">
					 	   		<option value="${tts}"><fmt:message key="${tts}" /></option>
					 	   	</c:forEach>
				 	    </select>
                    </div>
                    <a class="btn-flat success new-product" id="doSeach"><fmt:message key="i18n.serach"/></a>
                </div>
            </div>
            </form>
			<div class="row-fluid">
				<table class="table table-hover">
					<thead>
						<tr>
				        	<th><fmt:message key="i18n.type"/></th>
							<th><fmt:message key="i18n.jiaoyiUser"/></th>
							<th><fmt:message key="i18n.income"/></th>
							<th><fmt:message key="i18n.zhichu"/></th>
							<th><fmt:message key="i18n.operationTime"/></th>
							<th><fmt:message key="i18n.remark"/></th>
						</tr>
					</thead>
                    <tbody>
						<c:forEach items="${pageDTO.data}" var="data">
						<tr>
		   					<td><fmt:message key="${data.transactionType }"/></td>
							<td>${data.transactionObject}</td>
							<td><fmt:formatNumber value="${data.income}" pattern="#0.0000"/></td>
							<td><fmt:formatNumber value="${data.expenditure}" pattern="#0.0000"/></td>
							<td><fmt:formatDate value="${data.optDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
							<td>${data.remark}</td>
		   				</tr>
			   			</c:forEach>
						<c:if test="${empty pageDTO.data}">
						<tr>
							<td colspan="6" style="text-align: center;"><fmt:message key="i18n.noData"/></td>
						</tr>
						</c:if> 
                    </tbody>
				</table>
			</div>
			<div class="pagination">
				<ul>
		            <li><a href="${pageUrl }&pages=${pageDTO.page-1}">&#8249;</a></li>
		            <li><a <c:if test="${pageDTO.page eq 1}"> class="active" </c:if> href="${pageUrl }&pages=1">1</a></li>
		            <c:if test="${pageDTO.total ge 2}">
		            <li><a <c:if test="${pageDTO.page eq 2}"> class="active" </c:if> href="${pageUrl }&pages=2">2</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 2}">
		            <li><a <c:if test="${pageDTO.page eq 3}"> class="active" </c:if> href="${pageUrl }&pages=3">3</a></li>
		            </c:if>
		            <c:if test="${pageDTO.total ge 2}">
		            <li><a <c:if test="${pageDTO.page eq 4}"> class="active" </c:if> href="${pageUrl }&pages=4">4</a></li>
		            </c:if>
		            <li><span style="font-size: 10px;"> ${pageDTO.page}/${pageDTO.total} | <fmt:message key="i18n.total"/>${pageDTO.totalSize} </span></li>
		            <li><a href="${pageUrl }&pages=${pageDTO.page+1}">&#8250;</a></li>
		            
		            
	          	</ul>
	          	
	        </div>
		</div>
        <!-- end list table -->
        
	</div>
	
	<script type="text/javascript" src="../scripts/jquery-1.11.0.min.js"></script>

	<script>
		$(function(){
		    $("#doSeach").click(function(){
		    	$("#bonusSeachForm").submit();
		    });
		})
	</script>

</body>
</html>